What is to-absolute-glob?
The to-absolute-glob package is used to convert glob patterns into absolute paths. This is particularly useful when working with file system operations that require absolute paths. The package ensures that the glob patterns are resolved to absolute paths based on the process's current working directory or a specified base directory.
What are to-absolute-glob's main functionalities?
Convert relative glob to absolute
This feature allows you to convert a relative glob pattern into an absolute path glob pattern. The 'cwd' option specifies the base directory from which the glob should be resolved.
const toAbsoluteGlob = require('to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('*.js', { cwd: '/some/dir' });
console.log(absoluteGlob);
Handle negation patterns
The package can also handle negation patterns (patterns that start with '!') and convert them into absolute paths while preserving the negation.
const toAbsoluteGlob = require('to-absolute-glob');
const absoluteGlob = toAbsoluteGlob('!*.js', { cwd: '/some/dir' });
console.log(absoluteGlob);
Other packages similar to to-absolute-glob
globby
Globby is a user-friendly glob matching library that supports multiple patterns. It is built on top of the 'glob' and 'fast-glob' packages and provides a simpler API for matching files. It can also convert relative paths to absolute paths, similar to to-absolute-glob, but offers more features like expanding directories and array of patterns.
fast-glob
Fast-glob is a fast implementation of node's glob module that provides a similar functionality to to-absolute-glob. It supports absolute path resolution but is more focused on performance and additional features like stream API, error tolerance, and more extensive pattern matching capabilities.
to-absolute-glob
Make a glob pattern absolute, ensuring that negative globs and patterns with trailing slashes are correctly handled.
Install
Install with npm:
$ npm install --save to-absolute-glob
Usage
var toAbsGlob = require('to-absolute-glob');
toAbsGlob('a/*.js');
Examples
Given the current project folder (cwd) is /dev/foo/
:
makes a path absolute
toAbsGlob('a');
makes a glob absolute
toAbsGlob('a/*.js');
retains trailing slashes
toAbsGlob('a/*/');
retains trailing slashes with cwd
toAbsGlob('./fixtures/whatsgoingon/*/', {cwd: __dirname});
makes a negative glob absolute
toAbsGlob('!a/*.js');
from a cwd
toAbsGlob('a/*.js', {cwd: 'foo'});
makes a negative glob absolute from a cwd
toAbsGlob('!a/*.js', {cwd: 'foo'});
from a root path
toAbsGlob('/a/*.js', {root: 'baz'});
from a root slash
toAbsGlob('/a/*.js', {root: '/'});
from a negative root path
toAbsGlob('!/a/*.js', {root: 'baz'});
from a negative root slash
toAbsGlob('!/a/*.js', {root: '/'});
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Building docs
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
This file was generated by verb-generate-readme, v0.2.0, on October 17, 2016.